package other.mvvm.activity.src.app_package.viewpager

import com.android.tools.idea.wizard.template.ModuleTemplateData
import com.android.tools.idea.wizard.template.RecipeExecutor
import com.android.tools.idea.wizard.template.impl.activities.common.generateManifest
import other.mvvm.activity.res.layout.recyclerview.*
import other.mvvm.activity.res.layout.viewpager.viewpagerActivityXml
import other.mvvm.activity.src.app_package.mvvmRepository
import other.mvvm.activity.src.app_package.recyclerview.listBean
import other.mvvm.activity.src.app_package.recyclerview.listMvvmAcitivityKt
import other.mvvm.activity.src.app_package.recyclerview.listMvvmViewModel

fun RecipeExecutor.viewpagerActivityRecipe(
        moduleData: ModuleTemplateData,
        activityClass: String,
        layoutName: String,
        packageName: String
) {
    val (projectData, srcOut, resOut) = moduleData
    val ktOrJavaExt = projectData.language.extension
    generateManifest(
            moduleData = moduleData,
            activityClass = "${activityClass}Activity",
            packageName = packageName,
            isLauncher = false,
            hasNoActionBar = false,
            generateActivityTitle = true
    )

    val mvvmActivity = viewpagerMvvmAcitivityKt(projectData.applicationPackage, activityClass, packageName, arrayListOf<String>())
    // 保存Activity
    save(mvvmActivity, srcOut.resolve("${activityClass}Activity.${ktOrJavaExt}"))
    // 保存xml
    save(viewpagerActivityXml(packageName, activityClass), resOut.resolve("layout/${layoutName}.xml"))

    // 保存viewmodel
    save(viewpagerViewModel(packageName, activityClass), srcOut.resolve("${activityClass}ViewModel.${ktOrJavaExt}"))
    // 保存repository
    save(mvvmRepository(packageName, activityClass), srcOut.resolve("${activityClass}Repository.${ktOrJavaExt}"))
}